package com.yz.group1.group_1.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yz.group1.group_1.entity.AdminSchedule;
import com.yz.group1.group_1.mapper.AdminScheduleMapper;
import com.yz.group1.group_1.service.AdminScheduleService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 排班 Service 实现类，实现 AdminScheduleService 接口，继承 ServiceImpl 复用基础方法
 */
@Service
public class AdminScheduleServiceImpl extends ServiceImpl<AdminScheduleMapper, AdminSchedule> implements AdminScheduleService {

    @Override
    public boolean saveSchedule(AdminSchedule schedule) {
        return save(schedule);
    }

    @Override
    public boolean removeScheduleById(Long id) {
        return removeById(id);
    }

    @Override
    public boolean updateSchedule(AdminSchedule schedule) {
        return updateById(schedule);
    }

    @Override
    public AdminSchedule getScheduleById(Long id) {
        return getById(id);
    }

    @Override
    public List<AdminSchedule> listAllSchedules() {
        return list();
    }

    @Override
    public List<AdminSchedule> listSchedulesByDoctorId(Long doctorId) {
        // 使用 LambdaQueryWrapper 构建条件查询
        return lambdaQuery().eq(AdminSchedule::getDoctorId, doctorId).list();
    }

    @Override
    public List<AdminSchedule> listSchedulesByDeptId(Long deptId) {
        return lambdaQuery().eq(AdminSchedule::getDeptId, deptId).list();
    }

    @Override
    public List<AdminSchedule> listAllAdminSchedule() {
        return List.of();
    }



    //
    // AdminScheduleServiceImpl.java
    @Override
    public List<AdminSchedule> listByDeptAndDoctor(Long deptId, Long doctorId) {
        QueryWrapper<AdminSchedule> queryWrapper = new QueryWrapper<>();
        if (deptId != null) {
            queryWrapper.eq("dept_id", deptId);
        }
        if (doctorId != null) {
            queryWrapper.eq("doctor_id", doctorId);
        }
        return this.list(queryWrapper);
    }

}